#ifndef _PRESSANDHOLDBUTTON
#define _PRESSANDHOLDBUTTON

#include "WPILib.h"
#include "GenericButton.h"

/*
 * PressAndHoldButton.h
 * 
 * 
 * a class which monitors a button and only counts it pressed after a certain time
 */


class PressAndHoldButton : public GenericButton
{
public:
	// constructor based on a GenericButton (period defaults to 0.05)
	PressAndHoldButton(GenericButton *button, float period = 0.05);
	
	// set the time (in seconds) between samples
	void SetSampleRate(float period);
	// set how many samples the button must be held down to be considered pressed
	void SetNeededSamples(int number_of_samples);
	
	// has the button been pressed for the specefied amount?
	bool Get();
	
	/*
	 * Call the Update method as a non-static method.
	 * Do fancy stuff to setup the "this" pointer
	 */
	static void CallUpdate(void *ob);
	// this function is called periodically to monitor the status of the button and act accordingly
	void Update();
	
	// enable the button (it now responds to button pushes)
	void Enable();
	// disable the button (it now ignores button pushes)
	void Disable();
	
private:
	// initialize member variables, start Notifier
	void Init(float period);
	
	GenericButton *m_button;
	Notifier *m_controlLoop;
	
	bool m_enabled;			// default false
	bool m_pressed;
	int m_number_of_samples;
	int m_count;
};


#endif

